#!/bin/bash

# Copy js components
cp -r ../../../fbcode/staticdocs/websites/fbcref/src/components src

# Generate API documentation
# note the .*: --allowlist accepts python regexes
buck2 run //fbcref/docgen:maker -- \
  --fbcode-root ../.. \
  --project-roots .. \
  --doxyfile ../../fbcref/Doxyfile \
  --doxygen-output /tmp/doxygen_thrift_output \
  --website . \
  --ref-path ref/cpp \
  --allowlist \
    'thrift/lib/cpp/TProcessorEventHandler.h' \
    'thrift/lib/cpp/protocol/TCompactProtocol.*' \
    'thrift/lib/cpp2/protocol/Patch.h' \
    'thrift/lib/cpp2/FieldRef.h' \
    'thrift/lib/cpp2/op/.*'

# Make the table of contents
toc=$(cat << EOTOC
Hooks
  cpp/class/apache/thrift/TProcessorEventHandler

Serialization
  cpp/class/apache/thrift/protocol/TCompactProtocolT

Field Access
  cpp/class/apache/thrift/field_ref

Operator Library
  cpp/file/thrift/lib/cpp2/op/Clear.h
  cpp/file/thrift/lib/cpp2/op/Compare.h
  cpp/file/thrift/lib/cpp2/op/Copy.h
  cpp/file/thrift/lib/cpp2/op/Create.h
  cpp/file/thrift/lib/cpp2/op/Encode.h
  cpp/file/thrift/lib/cpp2/op/Get.h
  cpp/file/thrift/lib/cpp2/op/Hash.h
  cpp/file/thrift/lib/cpp2/op/Patch.h

Static Patch
  cpp/class/apache/thrift/op/detail/AssignPatch
  cpp/class/apache/thrift/op/detail/ListPatch
  cpp/class/apache/thrift/op/detail/SetPatch
  cpp/class/apache/thrift/op/detail/MapPatch
  cpp/class/apache/thrift/op/detail/FieldPatch
  cpp/class/apache/thrift/op/detail/StructPatch
  cpp/class/apache/thrift/op/detail/UnionPatch
  cpp/class/apache/thrift/op/detail/StringPatch
  cpp/class/apache/thrift/op/detail/BinaryPatch
  cpp/class/apache/thrift/op/detail/NumberPatch
  cpp/class/apache/thrift/op/detail/BoolPatch

Dynamic Patch
  cpp/file/thrift/lib/cpp2/protocol/Patch.h
EOTOC
)
python3 ../../fbcref/docgen/tocgen.py "$toc" > src/json/cpp_api_toc.json
